﻿<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeFile="Product.aspx.cs"
    Inherits="Product" ClientIDMode="Static" Culture="auto" UICulture="auto" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="Styles/formList.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #coverpic
        {
            display: inline-block;
            vertical-align: top;
            margin-top: 1em;
        }
        
        #shortInfo
        {
            display: inline-block;
            margin-left: 50px;
        }
        #shortInfo > *
        {
            margin: 1em 0;
        }
        #actionSection
        {
            display: table;
            width: 100%;
        }
        
        #actionSection > div
        {
            display: table-cell;
            text-align: center;
            width: 25%;
            vertical-align: bottom;
        }
        div#quantityArea
        {
            width: 50%;
        }
        #quantityActionArea
        {
            display: table;
            width: 100%;
        }
        
        #quantityActionArea > *
        {
            display: table-cell;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:SqlDataSource ID="ProductSource" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
        SelectCommand="SELECT aspnet_Users.UserName AS shopOwner, vw_DiscountedProduct.id, vw_DiscountedProduct.name, vw_DiscountedProduct.Price, vw_DiscountedProduct.Discount, vw_DiscountedProduct.Description, vw_DiscountedProduct.inventoryLevel, vw_DiscountedProduct.coverPhoto, vw_DiscountedProduct.category, vw_DiscountedProduct.DiscountedPrice FROM Shop INNER JOIN aspnet_Users ON Shop.owner = aspnet_Users.UserId INNER JOIN vw_DiscountedProduct ON Shop.name = vw_DiscountedProduct.Shop WHERE (vw_DiscountedProduct.id = @id)">
        <SelectParameters>
            <asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:Repeater ID="productRepeater" runat="server" DataSourceID="ProductSource" 
        >
        <ItemTemplate>
            <h2>
                <%# Title = Eval("name").ToString() %>
            </h2>
            <div id="coverpic">
                <asp:Image ID="Image1" runat="server" Height="96px" Width="96px" ImageUrl="~/Images/product.png" />
            </div>
            <div id="shortInfo">
                <ul class="formList">
                    <asp:Repeater ID="shortPropertyRepeater" runat="server" DataSourceID="ProductSource" onitemdatabound="shortPropertyRepeater_ItemDataBound">
                        <ItemTemplate>
                            <li><span>Owner</span> <span>
                            <%# Eval("shopOwner") %></span>
                                <asp:Button ID="Button1" runat="server" Text="Chat to me" />
                            </li>
                            <li><span>Price</span> <span><span>
                            <%# Eval( "DiscountedPrice","${0:.00}") %></span>
                            <asp:Label ID="originalPriceLabel" runat="server" Visible="false"/>
                                                       <%--                            <%# 
                            if(Eval("discount").Equals(0))
    Response.Write(string.Format("<span>(Original ${0}, discount {1})</span>",Eval("price"),Eval("discount")))
                            %>--%>
                            </span></li>
                            <li><span>
                            <%# Convert.ToInt32(Eval("inventoryLevel"))>0?"In Stock":"Out of Stock"%></span>
                            </li>
                            <li><span>Category</span><span><%# Eval("category") %></span></li>
                        </ItemTemplate>
                    </asp:Repeater>
                    <asp:SqlDataSource ID="salesRecordSource" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
                        SelectCommand="SELECT COUNT(*) AS Sold FROM Product INNER JOIN SalesItem ON Product.id = SalesItem.product INNER JOIN [Sale Record] ON SalesItem.salesRecord = [Sale Record].id AND Product.lastEditDate &lt; [Sale Record].completedDate WHERE (Product.id = @id) GROUP BY Product.id">
                        <SelectParameters>
                            <asp:QueryStringParameter Name="id" QueryStringField="id" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </ul>
            </div>
        </ItemTemplate>
    </asp:Repeater>
    <section id="actionSection">
        <div id="backToShopArea">
            <asp:SqlDataSource ID="backToShopSource" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
                SelectCommand="SELECT [Shop] FROM [Product] WHERE ([id] = @id)">
                <SelectParameters>
                    <asp:QueryStringParameter Name="id" QueryStringField="id" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:Repeater runat="server" DataSourceID="backToShopSource">
                <ItemTemplate>
                    <asp:Button runat="server" PostBackUrl='<%# "Shop.aspx?n="+Eval("Shop") %>' Text="Back to Shop" />
                </ItemTemplate>
            </asp:Repeater>
        </div>
        <div id="favoriteManipulationArea">
            <asp:Button ID="likeButton" runat="server" Text="Like" Visible="False" ViewStateMode="Disabled"
                OnClick="likeButton_Click" />
            <asp:Button ID="unlikeButton" runat="server" Text="Unlike" Visible="False" ViewStateMode="Disabled"
                OnClick="unlikeButton_Click" />
        </div>
        <div id="quantityArea">
            <div>
                <input type="hidden" id="productIdsField" runat="server" name="productId" clientidmode="Static" />
                Quantity&nbsp;
                <asp:TextBox ID="quantityTextBox" runat="server" ClientIDMode="Static">1</asp:TextBox>
                <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Type an interger"
                    ControlToValidate="quantityTextBox" Type="Integer" MinimumValue="1" MaximumValue="10000"
                    Display="Dynamic"></asp:RangeValidator>
            </div>
            <div id="quantityActionArea">
                <div id="cartManipulationArea">
                    <asp:Button ID="removeFromCartButton" runat="server" Text="Remove From Cart" Visible="False"
                        ViewStateMode="Disabled" OnClick="removeFromCartButton_Click" />
                    <asp:Button ID="addToCartButton" runat="server" Text="Add to Cart" Visible="False"
                        ViewStateMode="Disabled" OnClick="addToCartButton_Click" />
                </div>
                <div id="buyArea">
                    <asp:Button ID="buyButton" runat="server" Text="Buy Now" onclick="buyButton_Click" />
                </div>
            </div>
        </div>
    </section>
    <section id="proudctDescription">
    
    </section>
</asp:Content>
